<?php 
require_once("../../system/conf/config.php") ;
require_once($configs["framework_dir"]."/include/header_no.php") ;


$temp = get("primary_key") ;
$primaryKey = "";

$fields = array();
for($i=0;$i<count($temp);$i++){
	$property = array();
	if($temp[$i] == 1){
		$primaryKey = $_REQUEST["column_name"][$i];
	}

	$property["column_name"] = $_REQUEST["column_name"][$i];
	$property["primary_key"] = $_REQUEST["primary_key"][$i];
	$property["multiple_key"] = $_REQUEST["multiple_key"][$i];
	$property["numeric"] = $_REQUEST["numeric"][$i];
	$property["unique_key"] = $_REQUEST["unique_key"][$i];
	$property["unsigned"] = $_REQUEST["unsigned"][$i];
	$property["zerofill"] = $_REQUEST["zerofill"][$i];
	$property["max_length"] = $_REQUEST["max_length"][$i];
	$property["field_name"] = $_REQUEST["field_name"][$i];
	$property["r_type"] = $_REQUEST["r_type"][$i];
	$property["not_null"] = $_REQUEST["not_null"][$i];
	$property["searchable"] = $_REQUEST["searchable"][$i];
	$property["listable"] = $_REQUEST["listable"][$i];
	$property["width"] = $_REQUEST["width"][$i];
	$property["remark"] = $_REQUEST["remark"][$i];
	$property["type"] = $_REQUEST["type"][$i];
	$property["search_name"] = "search_lk_a__".$_REQUEST["column_name"][$i] ;
	$property["element_name"] = ($property["type"]=="bit"?"ignore_":"") . $property["column_name"] ;
	$property["common"] = getFieldCommonFlag($property);
	$property["hidden"] = getFieldHiddenFlag($property);
	$property["edit_html"] = getFieldEditHtml($property);
	$property["label_name"] = getFieldLabelName($_REQUEST["tableName"],$property) ;
	$property["star"] = $property["not_null"] ? "*":"";

	array_push($fields,$property);
}

$list_size = 1;
$query_columns = "";

for($i=0;$i<count($fields);$i++){
	if($fields[$i]["listable"] == 1){
		$list_size++ ;
		$query_columns .= ($query_columns != "") ? "," : "" ;
		$query_columns .= "a." . $fields[$i]["column_name"] ;
	}
}

include "../../raintpl 2.6.4/inc/rain.tpl.class.php";
raintpl::configure("base_url", null );
raintpl::configure("tpl_dir", "../../system/auto_generate/" );
raintpl::configure("cache_dir", "../../system/auto_generate/tmp/" );

//initialize a Rain TPL object
$tpl = new RainTPL;
$tpl->assign( "php_begin", "<?php" );
$tpl->assign( "php_end", "?>" );
$tpl->assign( "php_short_begin", "<?=" );
$tpl->assign( "tab", "\t" );
$tpl->assign( "crlf", "\r\n" );
$tpl->assign( "primaryKey", $primaryKey );
$tpl->assign( "tableName", get("tableName") );
$tpl->assign( "entityName", get("entityName") );
$tpl->assign( "targetFolder", get("targetFolder") );
$tpl->assign( "fields", $fields );
$tpl->assign( "label_page_name", get("tableName")."_labels.php" );
$tpl->assign( "js_page_name", get("tableName").".js" );
$tpl->assign( "js_include", '<script language="JavaScript" src="'.get("tableName").'.js"></script>');
$tpl->assign( "list_page_name", get("tableName")."_list.php" );
$tpl->assign( "edit_page_name", get("tableName")."_edit.php" );
$tpl->assign( "basic_info_page_name", get("tableName")."_basic_info.php" );
$tpl->assign( "list_size", $list_size );
$tpl->assign( "query_columns", $query_columns );


function generate($tpl,$template,$dist){
	$html = $tpl->draw($template, $return_string = true );
	rewriteFile($dist,$html,"utf8",false);
}

$tableName = get("tableName");

generate($tpl,"template_list",get("targetFolder")."/".$tableName."_list.php");
generate($tpl,"template_edit",get("targetFolder")."/".$tableName."_edit.php");
generate($tpl,"template_do",get("targetFolder")."/".$tableName."_do.php");
generate($tpl,"template_js",get("targetFolder")."/".$tableName.".js");
generate($tpl,"template_basicinfo",get("targetFolder")."/".$tableName."_basicinfo.php");
generate($tpl,"template_labels",getRealPath("../../system/labels")."/".$tableName."_labels.php");

?>

<BR><BR>

<input type=button class='btn bback' value='Back' onclick="go_url('autopage_1.php')">
<input type=button class='btn brefresh' value='Refresh' onclick="do_refresh()">

<?php
require_once($configs["framework_dir"]."/include/footer_no.php") ;
?>